#include "stdafx.h"
#include "Fakes/FakeD3D11Device.h"
#include "Fakes/FakeD3D11SamplerState.h"

DESCRIPTION_11_TEST_SUITE(SamplerDescription)

BOOST_FIXTURE_TEST_CASE(Default, TestSamplerDescription)
{
	BOOST_REQUIRE_EQUAL(D3D11_FILTER_MIN_MAG_MIP_POINT, m_desc.Filter);
	BOOST_REQUIRE_EQUAL(D3D11_TEXTURE_ADDRESS_CLAMP, m_desc.AddressU);
	BOOST_REQUIRE_EQUAL(D3D11_TEXTURE_ADDRESS_CLAMP, m_desc.AddressV);
	BOOST_REQUIRE_EQUAL(D3D11_TEXTURE_ADDRESS_CLAMP, m_desc.AddressW);
	BOOST_REQUIRE_EQUAL(0.0f, m_desc.MipLODBias);
	BOOST_REQUIRE_EQUAL(16, m_desc.MaxAnisotropy);
	BOOST_REQUIRE_EQUAL(D3D11_COMPARISON_NEVER, m_desc.ComparisonFunc);
	BOOST_REQUIRE_EQUAL(0.0f, m_desc.BorderColor[0]);
	BOOST_REQUIRE_EQUAL(0.0f, m_desc.BorderColor[1]);
	BOOST_REQUIRE_EQUAL(0.0f, m_desc.BorderColor[2]);
	BOOST_REQUIRE_EQUAL(0.0f, m_desc.BorderColor[3]);
	BOOST_REQUIRE_EQUAL(-FLT_MAX, m_desc.MinLOD);
	BOOST_REQUIRE_EQUAL(FLT_MAX, m_desc.MaxLOD);
}

#define SAMPLER_DESCRIPTION_TEST_CASE(type_, name_, value_)		\
	DESCRIPTION_11_SETTER_FIXTURE_TEST_CASE(name_##_, SamplerDescription,	\
		type_, value_, name_)

SAMPLER_DESCRIPTION_TEST_CASE(D3D11_FILTER, Filter, D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT)
SAMPLER_DESCRIPTION_TEST_CASE(D3D11_TEXTURE_ADDRESS_MODE, AddressU, D3D11_TEXTURE_ADDRESS_BORDER)
SAMPLER_DESCRIPTION_TEST_CASE(D3D11_TEXTURE_ADDRESS_MODE, AddressV, D3D11_TEXTURE_ADDRESS_BORDER)
SAMPLER_DESCRIPTION_TEST_CASE(D3D11_TEXTURE_ADDRESS_MODE, AddressW, D3D11_TEXTURE_ADDRESS_BORDER)
SAMPLER_DESCRIPTION_TEST_CASE(float, MipLODBias, 2)
SAMPLER_DESCRIPTION_TEST_CASE(UINT, MaxAnisotropy, 2)
SAMPLER_DESCRIPTION_TEST_CASE(D3D11_COMPARISON_FUNC, ComparisonFunc, D3D11_COMPARISON_ALWAYS)
SAMPLER_DESCRIPTION_TEST_CASE(float, MinLOD, 2.0f)
SAMPLER_DESCRIPTION_TEST_CASE(float, MaxLOD, 2.0f)

static void AssertBorderColor(rt::D3D11::SamplerDescription &desc, UINT index)
{
	float borderColor = desc.BorderColor_(index, 0.25f).BorderColor[index];
	BOOST_REQUIRE_EQUAL(0.25f, borderColor);
}

BOOST_FIXTURE_TEST_CASE(BorderColor0, TestSamplerDescription) { AssertBorderColor(m_desc, 0); }
BOOST_FIXTURE_TEST_CASE(BorderColor1, TestSamplerDescription) { AssertBorderColor(m_desc, 1); }
BOOST_FIXTURE_TEST_CASE(BorderColor2, TestSamplerDescription) { AssertBorderColor(m_desc, 2); }
BOOST_FIXTURE_TEST_CASE(BorderColor3, TestSamplerDescription) { AssertBorderColor(m_desc, 3); }

BOOST_FIXTURE_TEST_CASE(Create_, TestSamplerDescription)
{
	FakeD3D11Device device;
	FakeD3D11SamplerState state;
	device.CreateSamplerStateFakeResult = &state;
	device.CreateSamplerStateFakeHResult = S_OK;
	ID3D11SamplerState *result = m_desc.Create(&device);
	BOOST_REQUIRE(device.CreateSamplerStateCalled);
	BOOST_REQUIRE_EQUAL(&m_desc, device.CreateSamplerStateLastDesc);
	BOOST_REQUIRE_EQUAL(&state, result);
}

BOOST_AUTO_TEST_SUITE_END()
